package org.cloud.service.Impl;

import org.cloud.mapper.CategoryMapper;
import org.cloud.mapper.CategoryMapperCustom;
import org.cloud.pojo.Carousel;
import org.cloud.pojo.Category;
import org.cloud.service.CategoryService;
import org.cloud.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.HashMap;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private CategoryMapperCustom categoryMapperCustom;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Category> queryAllRootLevelCat() {

        Example example = new Example(Carousel.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("type",1);
        List<Category> result = categoryMapper.selectByExample(example);

        return result;
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    public List<CategoryVo> getSubCatList(Integer rootCatId) {
        List<CategoryVo> subCatList = categoryMapperCustom.getSubCatList(rootCatId);
        return subCatList;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List getSixNewItemsLazy(Integer rootCatId) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("rootCatId",rootCatId);
        return categoryMapperCustom.getSixNewItemsLazy(map);
    }
}
